package home.control.data;

import home.control.logicElements.Action;
import home.control.logicElements.ActionTypes;
import home.control.logicElements.HomeParts;
import home.control.logicElements.Plan;
import java.util.*;

public class FactoryData implements IGetData {

	List<Plan> planList= new ArrayList<Plan>();
	private static FactoryData instance;
	
	public static synchronized FactoryData getInstance(){
		if(instance == null){
			return new FactoryData();
		}else{
			return instance;
		}
	}
	
	private FactoryData(){
//		//Tworzenie planu 1
//		Plan plan1 = new Plan();
//		plan1.setName("Zwykły");
//		plan1.setActive(true);
//		plan1.addAction( new Action(HomeParts.KITCHEN_LIGHTS, ActionTypes.TURN_ON_LIGHTS, new Date(0,0,0,20,15,0)));
//		plan1.addAction( new Action(HomeParts.BATHROOM_LIGHTS, ActionTypes.TURN_OFF_LIGHTS, new Date(0,0,0,22,15,0)));
//		planList.add(plan1);
//		
//		//Tworzenie planu 2
//		Plan plan2 = new Plan();
//		plan2.setName("Świąteczny");
//		plan2.addAction( new Action(HomeParts.LIVING_LIGHTS, ActionTypes.TURN_ON_LIGHTS, new Date(0,0,0,8,15,0)));
//		plan2.addAction( new Action(HomeParts.ALL_HOUSE, ActionTypes.HEATING_18, new Date(0,0,0,1,0,0)));
//		plan2.addAction( new Action(HomeParts.ALL_HOUSE, ActionTypes.HEATING_20, new Date(0,0,0,7,5,0)));
//		plan2.addAction( new Action(HomeParts.KITCHEN_LIGHTS, ActionTypes.TURN_ON_LIGHTS, new Date(0,0,0,8,15,0)));
//		plan2.addAction( new Action(HomeParts.KITCHEN_LIGHTS, ActionTypes.TURN_OFF_LIGHTS, new Date(0,0,0,10,15,0)));
//		plan2.addAction( new Action(HomeParts.ALL_HOUSE, ActionTypes.HEATING_20, new Date(0,0,0,17,15,0)));
//		plan2.addAction( new Action(HomeParts.ALL_HOUSE, ActionTypes.HEATING_OFF, new Date(0,0,0,10,15,0)));
//		plan2.setActive(false);
//		planList.add(plan2);
	}
	
	@Override
	public List<Plan> getAllPlans() {
		return planList;
	}


	public void add(Plan selectedItem, Action action) {
		int index = planList.indexOf(selectedItem);
		Plan p = planList.get(index);
		p.addAction(action);
	}


	public void removeActionFromPlan(Plan selectedItem, Action action) {
		int index = planList.indexOf(selectedItem);
		Plan p = planList.get(index);
		p.removeAction(action);
		
	}

	public List<HomeParts> getInstantActions() {
		List<HomeParts> ia = new ArrayList<HomeParts>();
		ia.add(HomeParts.BATHROOM_LIGHTS);
		ia.add(HomeParts.LIVING_LIGHTS);
		ia.add(HomeParts.KITCHEN_LIGHTS);
		ia.add(HomeParts.SECURITY);
		return ia;
	}


	public void setTemperature(ActionTypes heatingOff) {
		// TODO Auto-generated method stub
		
	}
	
	public ActionTypes getTemperature(){
		return ActionTypes.HEATING_20;
	}

	@Override
	public boolean checkStatus(HomeParts homePart) {
		Random r = new Random();
		return r.nextBoolean();
	}

	@Override
	public void setStatus(HomeParts homePart, boolean status) {
		//TODO Ustawia status światła.
	}


	@Override
	public void addPlan(Plan p) {
		planList.add(p);
	}

	@Override
	public void setActivePlan(Plan p) {
		int index = planList.indexOf(p);
		Plan pl = planList.get(index);
		for(Plan p1 : planList){
			p1.setActive(false);
		}
		pl.setActive(true);
		

	}

	@Override
	public boolean login(String host, String pass) {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean getAlarm() {
		// TODO Auto-generated method stub
		return false;
	}
}
